const { Tab } = require('../../assets/libs/zanui/index');

var app = getApp();
Page(Object.assign({}, Tab, {
  data: {
    bannerList: [{ image: "/assets/images/swipe/1.jpg" }, { image: "/assets/images/swipe/2.jpg" }, { image: "/assets/images/swipe/3.jpg" }, { image: "/assets/images/swipe/4.jpg" }],
    archivesList: [],
    loading: false,
    nodata: false,
    nomore: false,
    tab: {
      list: [],
      selectedId: '0',
      scroll: true,
      height: 44
    },
  },
  model: 2,
  channel: 0,
  page: 1,
  onLoad: function () {
    var that = this;
    this.channel = 0;
    this.page = 1;
    // this.setData({ ["tab.list"]: app.globalData.indexTabList });
    // app.request('/index/index', {}, function (data, ret) {
    //   that.setData({
    //     bannerList: data.bannerList,
    //     archivesList: data.archivesList 
    //   });

    // }, function (data, ret) {
    //   app.error(ret.msg);
    // });

    that.loadArchives();
  },
  onPullDownRefresh: function () {
    this.setData({ nodata: false, nomore: false });
    this.page = 1;
    this.loadArchives(function () {
      wx.stopPullDownRefresh();
    });
  },
  onReachBottom: function () {
    var that = this;
    this.loadArchives(function (data) {
      if (data.archivesList.length == 0) {
        app.info("暂无更多数据");
      }
    });
  },
  loadArchives: function (cb) {
    var that = this;
    if (that.data.nomore == true || that.data.loading == true) {
      return;
    }
    this.setData({ loading: true });
    app.getData('/getVendors' ,[],"get", function (res) {
      that.setData({ 
        archivesList: res.data.data.records,
      }); 
      
    } );
  },

  handleZanTabChange(e) {
    var componentId = e.componentId;
    var selectedId = e.selectedId;
    this.channel = selectedId;
    this.page = 1;
    this.setData({
      nodata: false,
      nomore: false,
      [`${componentId}.selectedId`]: selectedId
    });
    wx.pageScrollTo({ scrollTop: 0 });
    this.loadArchives();
  },
  onShareAppMessage: function () {
    return {
      title: ' ',
      desc: ' ',
      path: ' '
    }
  }
}))